package logics
{
	import global.Managers;
	
	import lang.LanguageManager;
	
	import net.servers.ServerManager;
	
	import vo.DishType;
	import vo.DishVO;
	
	public class DishManager
	{
		public var dishes				: Array = [];
		
		public function DishManager()
		{
		}
		public function init(serverManager:ServerManager):void {
			serverManager.subscribe("Dishes", getDishesHandler);
			serverManager.send("GetDishes");
		}
		private function getDishesHandler(data:Object):void {
			this.dishes.splice(0, this.dishes.length);
			var dishes:Array = data as Array;
			for(var i:int = 0; i < dishes.length; i++) {
				var dish:Object = dishes[i];
				var dishVO:DishVO = new DishVO();
				dishVO.id = dish.id;
				dishVO.name = dish.name;
				dishVO.type = dish.type;
				dishVO.price = dish.price;
				dishVO.image = "dishes/" + dish.image;
				dishVO.hasMeat = (dish.hasMeat == 1);
				dishVO.hasGlucose = (dish.hasGlucose == 1);
				dishVO.stackable = (dish.stackable == 1);
				dishVO.customizable = (dish.customizable == 1);
				dishVO.describe = dish.describe;
				this.dishes.push(dishVO);
			}
		}
		
		public function getValueByID(id:int):DishVO {
			var dishVO:DishVO;
			for each(var value:DishVO in dishes) {
				if(value.id == id) {
					dishVO = value;
					break;
				}
			}
			return dishVO;
		}
		public function getTypeName(type:int):String {
			var manager:LanguageManager = Managers.languageManager;
			var name:String;
			switch(type) {
				case DishType.STAPLE:
					name = manager.getLanguageText("staple");
					break;
				case DishType.CODE_DISHES:
					name = manager.getLanguageText("code_dishes");
					break;
				case DishType.HOT_DISHES:
					name = manager.getLanguageText("hot_dishes");
					break;
				case DishType.DESSERT:
					name = manager.getLanguageText("dessert");
					break;
				case DishType.SOAP:
					name = manager.getLanguageText("soap");
					break;
				case DishType.DRINKS:
					name = manager.getLanguageText("drinks");
					break;
				case DishType.OTHERS:
					name = manager.getLanguageText("others");
					break;
			}
			return name;
		}
	}
}